//
//  SXReadRootViewController.m
//  ShiXun
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 张琪. All rights reserved.
//

#import "SXReadRootViewController.h"
#import "SXReadRecommendViewController.h"
#import "SXMyReadTableViewController.h"

@interface SXReadRootViewController ()

@property (nonatomic, strong) UISegmentedControl *segmentControl;
@property (nonatomic, strong) SXReadRecommendViewController *readRecommendVC; // 推荐阅读
@property (nonatomic, strong) SXMyReadTableViewController *myReadTabelVC; // 我的订阅

@end

@implementation SXReadRootViewController

- (UISegmentedControl *)segmentControl
{
    if (!_segmentControl) {
        _segmentControl = [[UISegmentedControl alloc] initWithItems:@[@"推荐阅读", @"我的阅读"]];
        _segmentControl.frame = CGRectMake(kScreenWidth / 2 - 80, 10, 160, 20);
        _segmentControl.selectedSegmentIndex = 0;
        [_segmentControl addTarget:self action:@selector(changeView) forControlEvents:(UIControlEventValueChanged)];
    }
    return _segmentControl;
}

- (void)changeView
{
    if (_segmentControl.selectedSegmentIndex == 0) {
        [self.myReadTabelVC.view removeFromSuperview];
        [self.view addSubview:self.readRecommendVC.view];
    }
    else{
        [self.readRecommendVC.view removeFromSuperview];
        [self.view addSubview:self.myReadTabelVC.view];
    }
}

- (SXReadRecommendViewController *)readRecommendVC
{
    if (!_readRecommendVC) {
        _readRecommendVC = [[SXReadRecommendViewController alloc] init];
        _readRecommendVC.readRootVC = self;
        _readRecommendVC.view.frame = CGRectMake(0, 104, kScreenWidth, kScreenHeight - 153);
    }
    return _readRecommendVC;
}

- (SXMyReadTableViewController *)myReadTabelVC
{
    if (!_myReadTabelVC) {
        _myReadTabelVC = [[SXMyReadTableViewController alloc] init];
        _myReadTabelVC.readRootVC = self;
        _myReadTabelVC.view.frame = CGRectMake(0, 104, kScreenWidth, kScreenHeight - 153);
    }
    return _myReadTabelVC;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    // Do any additional setup after loading the view.
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, kScreenWidth, 40)];
    [headView addSubview:self.segmentControl];
    [self.view addSubview:headView];
    
    
    [self.view addSubview:self.readRecommendVC.view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
